function succ = bvxcreatefile(filename)
% bvxcreatefile  - create new BVX file
%
% FORMAT:       [succ = ] bvxcreatefile(filename)
%
% Input fields:
%
%       filename    filename of BVX file to create
%
% Output fields:
%
%       succ        success

% Version:  v0.7f
% Build:    8110521
% Date:     Nov-05 2008, 9:00 PM CET
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% default
succ = false;

% argument check
if nargin < 1 || ...
   ~ischar(filename) || ...
    numel(filename) < 5 || ...
    numel(filename) ~= size(filename, 2)
    return;
end
if ~strcmpi(filename(end-3:end), '.bvx')
    return;
end

% file already exists
if exist(filename, 'file') == 2
    try
        delete(filename);
    catch
        % do nothing
    end
    if exist(filename, 'file') == 2
        return;
    end
end

% try creation
bvx = [];
try
    bvx = bless(BVQXfile('new:bvx'), 1);
    bvx.SaveAs(filename);
catch
    % do nothing
end
if ~isempty(bvx)
    try
        bvx.ClearObject;
    catch
        % do nothing
    end
end
if exist(filename, 'file') == 2
    succ = true;
end
